// 封装所有用户相关的请求
import request from '@/utils/request.js'

/**
 *  登录请求
 * @param { Object } data { mobile : '', code : '' }
 */
export const login = data => {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}
/**
 * 获取短信验证码
 * @param {*} mobile 手机号
 * @returns
 */
export const sendCode = mobile => {
  return request({
    method: 'GET',
    url: '/v1_0/sms/codes/' + mobile
  })
}
/**
 * 获取用户自己信息
 */
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
  })
}
/**
 * 获取用户频道列表
 */
export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

/**
 * 取消关注用户
 * @param {Number} target 目标用户（被取消关注的用户id）
 * @returns promise
 */
export const deleteUserFollowed = target => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
}

/**
 * 关注用户
 * @param {Number} target 关注目标（被关注的用户id)
 * @returns promise
 */
export const addUserFollowed = target => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 获取用户个人资料
 * @returns promise
 */
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/**
 * 编辑用户个人资料
 * @param {Object} data photo name gender birthday
 * @returns promise
 */
export const editUserProfile = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

/**
 * 编辑用户头像
 * @param {Object} data 表单数据对象
 * @returns promise
 */
export const editUserAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}

/**
 * 刷新用户token
 * @returns promise
 */
export const getToken = () => {
  return request({
    method: 'PUT',
    url: '/v1_0/authorizations'
  })
}
